#!/bin/bash
#
#cal some project someone edit lines
#
project_url='/root/Desktop/jenkins_private'
cal_date=`date +%Y-%m-%d`
long_time="24 hours ago"
#yes_date=`date +%Y-%m-%d -d "-1 days"`
#yes_date="2016-08-06"
#tor_date=`date +%Y-%m-%d -d "+1 days"`
#tor_date="2016-08-08"
file_path="/var/log/git_cal.log"
#
cd ${project_url}
#cal user who write code in  24 hours
#user_list=`git log --after=${yes_date} --before=${tor_date} --pretty=format:%an |uniq`
user_list=`git log --after="${long_time}" --pretty=format:%an |uniq`
#cal code lines
user_code_lines()
{
for user in ${user_list};do
#    insert_lines=`git log --author=${user} -p --after=${yes_date} --before=${tor_date}| grep  ^+ | grep -v "+++"| wc -l`
#    delete_lines=`git log --author=${user} -p --after=${yes_date} --before=${tor_date}| grep -E ^- | grep -v "\\---"| wc -l`
    insert_lines=`git log --author=${user} -p --after="${long_time}" | grep  ^+ | grep -v "+++"| wc -l`
    delete_lines=`git log --author=${user} -p --after="${long_time}" | grep -E ^- | grep -v "\\---"| wc -l`
    echo -e "${cal_date}\t${user}\t${insert_lines}\t${delete_lines}" >> $file_path
    mysql -u root -pqwe123 -D test <<EOF
	insert into git (insert_date,user,add_lines,del_lines) values ("${cal_date}","${user}","${insert_lines}","${delete_lines}")
EOF
#    mysql -u root -pqwe123 -D test -e "insert into git_char (insert_date,user,add_lines,del_lines) values ('${cal_date}','${user}','${insert_lines}','${delete_lines}')"
done
}
user_code_lines
